<?php
header("Content-Type:text/html; charset=utf-8"); 
include 'includes/utilities.php';
$link = OpenDB();
$search = mysql_real_escape_string($_POST["q"]);
$search = str_ireplace ( "á","%" , $search);
$search = str_ireplace ( "é","%" , $search);
$search = str_ireplace ( "í","%" , $search);
$search = str_ireplace ( "ó","%" , $search);
$search = str_ireplace ( "ú","%" , $search);
$search = str_ireplace ( "ñ","%" , $search);
$query = "select codigo as id from nomenclador 
    where codigo like '%".$search."%' or descripcion like '%".$search."%'";
$nomencladores = GetSQL($query);
$valores = "";
foreach($nomencladores as $nomenclador)
{
    $valores .=  '{"id":"'.utf8_encode($nomenclador["id"]).'", "name":"'.utf8_encode($nomenclador["id"]).'"},';
}
$valores = rtrim($valores, ",");
?>
[<?= $valores ?>]
